home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1327
/
refcount.dpr
< prev
next >
Wrap
Text File
|
1997-06-26
|
4KB
|
122 lines
{******************************************************}
{ RefCount v1.0 }
{ Copyright (c) 1997 Magnus BΣck }
{ baeck@swipnet.se }
{******************************************************}
{ This software may be distributed and modified freely }
{ as long as the original copyright is not removed and }
{ no profit is made from it. }
{******************************************************}
program RefCount;
uses SysUtils,
Classes,
Registry,
Windows;
{$R *.RES}
{$R RC_RES.RES}
{$APPTYPE CONSOLE}
const
ProductName = 'RefCount';
Version = 'v1.0';
Copyright = 'Copyright (c) 1997 Magnus Bäck';
var
CalculatedParamCount, CurrData, I, J: Integer;
Registry: TRegistry;
Values: TStringList;
CurrValue: string;
BinaryData: array [0..3] of Char;
PrintedLine, DoAll, DoClean: Boolean;
begin
if ParamCount = 0 then
begin
Writeln(Format('%s %s %s',[ProductName,Version,Copyright]));
Writeln;
Writeln('Syntax: REFCOUNT.EXE [/CLEAN] {/ALL | <filename> ...}');
Writeln;
Writeln('Use: Returns the system reference count of <filename>.');
Writeln(' This is stored in the registry in');
Writeln(' HKML\SOFTWARE\Microsoft\Windows\CurrentVersion\' +
'SharedDLLs.');
Writeln(' /CLEAN also removes all zero reference counts');
Writeln(' while /ALL displays all values.');
Halt(1);
end;
DoAll := False;
DoClean := False;
for I := 1 to ParamCount do
begin
if AnsiLowerCase(ParamStr(I)) = '/clean' then
DoClean := True;
if AnsiLowerCase(ParamStr(I)) = '/all' then
DoAll := True;
end;
Registry := TRegistry.Create;
try
Registry.RootKey := HKEY_LOCAL_MACHINE;
if not Registry.OpenKey('SOFTWARE\Microsoft\Windows\' +
'CurrentVersion\SharedDLLs',False) then
begin
Writeln('Error: Could not open key HKLM\SOFTWARE\Microsoft\'+
'Windows\CurrentVersion\SharedDLLs');
Halt(1);
end;
Values := TStringList.Create;
try
Registry.GetValueNames(Values);
if DoAll then
CalculatedParamCount := ParamCount + 1
else
CalculatedParamCount := ParamCount;
for I := 1 to CalculatedParamCount do
begin
if (AnsiLowerCase(ParamStr(I)) = '/clean') or
(AnsiLowerCase(ParamStr(I)) = '/all') then
Continue;
J := 0;
while J < Values.Count do
begin
PrintedLine := False;
CurrValue := Values[J];
case Registry.GetDataType(CurrValue) of
rdInteger: CurrData := Registry.ReadInteger(CurrValue);
rdString: CurrData := StrToInt(Registry.ReadString(CurrValue));
rdBinary:
begin
Registry.ReadBinaryData(CurrValue,BinaryData,4);
CurrData := Ord(BinaryData[0]);
end;
end;
if DoAll or ((ExtractFilePath(ParamStr(I)) = '') and
(AnsiLowerCase(ExtractFileName(CurrValue)) =
AnsiLowerCase(ParamStr(I)))) or
((ExtractFilePath(ParamStr(I)) <> '') and
(AnsiLowerCase(CurrValue) = AnsiLowerCase(ParamStr(I)))) then
begin
Write(Format('%-60s %-2d (0x%1:.4x)',[CurrValue,CurrData]));
PrintedLine := True;
end;
if DoClean and PrintedLine and (not FileExists(CurrValue)) then
begin
Registry.DeleteValue(CurrValue);
Write(' Deleted');
end
else if PrintedLine then
Writeln;
Inc(J);
end;
end;
finally
Values.Free;
end;
finally
Registry.CloseKey;
Registry.Free;
end;
end.